<template>
  <div class="live-card" @click="$emit('click')">
    <div class="cover-wrapper">
      <van-image :src="live.cover" class="cover" fit="cover" />
      <div class="live-status" :class="{ 'is-replay': live.type === 'replay' }">
        {{ live.type === 'live' ? '直播中' : '回放' }}
      </div>
      <div class="views">
        <van-icon name="eye-o" />
        <span>{{ formatNumber(live.views) }}</span>
      </div>
    </div>
    <div class="info">
      <div class="title">{{ live.title }}</div>
      <div class="uploader">
        <van-image :src="live.avatar" round width="20" height="20" />
        <span>{{ live.uploader }}</span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { formatNumber } from '@/utils/format'

interface LiveItem {
  id: string | number
  title: string
  cover: string
  url: string
  type: 'live' | 'replay'
  views: number
  uploader: string
  avatar: string
}

defineProps<{
  live: LiveItem
}>()

defineEmits<{
  (e: 'click'): void
}>()
</script>

<style scoped lang="less">
.live-card {
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;

  .cover-wrapper {
    position: relative;
    width: 100%;
    padding-top: 56.25%; // 16:9 比例

    .cover {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
    }

    .live-status {
      position: absolute;
      top: 8px;
      right: 8px;
      padding: 2px 6px;
      background: #ff4d4f;
      color: #fff;
      border-radius: 4px;
      font-size: 12px;

      &.is-replay {
        background: #666;
      }
    }

    .views {
      position: absolute;
      left: 8px;
      bottom: 8px;
      color: #fff;
      font-size: 12px;
      text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
      display: flex;
      align-items: center;
      gap: 4px;
    }
  }

  .info {
    padding: 8px;

    .title {
      font-size: 14px;
      color: #333;
      line-height: 1.4;
      margin-bottom: 8px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }

    .uploader {
      display: flex;
      align-items: center;
      gap: 6px;
      font-size: 12px;
      color: #666;
    }
  }
}
</style>
